/*
 *    Copyright (c) 2018-2025, boss All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the boss developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: boss
 */
package com.hopes.bizz.close.visitor.service.impl;

import cn.hutool.core.util.ObjUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
import com.hopes.bizz.close.visitor.entity.ClosedApplyGoodsRelEntity;
import com.hopes.bizz.close.visitor.entity.ClosedHazardCarApplyEntity;
import com.hopes.bizz.close.visitor.mapper.ClosedApplyGoodsRelMapper;
import com.hopes.bizz.close.visitor.mapper.ClosedHazardCarApplyMapper;
import com.hopes.bizz.close.visitor.service.ClosedApplyGoodsRelService;
import com.hopes.bizz.close.visitor.service.ClosedHazardCarApplyService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * 物流单危化品关系
 *
 * @author pig
 * @date 2024-02-17 15:35:17
 */
@Service
@RequiredArgsConstructor
public class ClosedApplyGoodsRelServiceImpl extends ServiceImpl<ClosedApplyGoodsRelMapper, ClosedApplyGoodsRelEntity> implements ClosedApplyGoodsRelService {

    private final ClosedHazardCarApplyMapper closedHazardCarApplyMapper;

    @Override
    public boolean save(ClosedApplyGoodsRelEntity entity) {
        if (ObjUtil.isNull(entity.getOrgId()) && ObjUtil.isNotNull(entity.getApplyId())) {
            final ClosedHazardCarApplyEntity hazardCarApply = closedHazardCarApplyMapper.selectById(entity.getApplyId());
            entity.setOrgId(hazardCarApply.getOrgId());
        }
        return SqlHelper.retBool(getBaseMapper().insert(entity));
    }


}
